/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src;

import src.domain.security.Policy;
import src.util.Constanta;

/**
 *
 * @author Yusup Jauhari Shandi <chan at In.Visi Forever!>
 */

public class Menu implements java.io.Serializable{
    private Integer menuId;
    private String menuGroup;
    private String menuType;
    private String menuName;
    private String menuNameEn;
    private String url;
    private String policy;    
    private Integer parentId;
    private Integer hide;
    private Policy policyAction;
    private Policy groupPolicyAction;
    private Integer disabled;
    private String beanname;

    public Menu() {
        this.policyAction = new Policy();
        this.groupPolicyAction = new Policy();
    }

    public Menu(Integer menuId, String menuGroup, String menuType, String menuName, String menuNameEn, String url, String policy, Integer parentId,String beanname) {
        this.menuId = menuId;
        this.menuGroup = menuGroup;
        this.menuType = menuType;
        this.menuName = menuName;
        this.menuNameEn = menuNameEn;
        this.url = url;
        this.policy = policy;
        this.parentId = parentId;
        this.beanname = beanname;
        this.policyAction = new Policy();
        this.groupPolicyAction = new Policy();
    }

    public String getBeanname() {
        return beanname;
    }

    public void setBeanname(String beanname) {
        this.beanname = beanname;
    }

    
    public Integer getDisabled() {
        return disabled;
    }

    public void setDisabled(Integer disabled) {
        this.disabled = disabled;
    }
    
    

    public Integer getHide() {
        return hide;
    }

    public void setHide(Integer hide) {
        this.hide = hide;
    }

    public String getMenuGroup() {
        return menuGroup;
    }

    public void setMenuGroup(String menuGroup) {
        this.menuGroup = menuGroup;
    }

    public Integer getMenuId() {
        return menuId;
    }

    public void setMenuId(Integer menuId) {
        this.menuId = menuId;
    }

    public String getMenuName() {
        return menuName;
    }

    public void setMenuName(String menuName) {
        this.menuName = menuName;
    }

    public String getMenuNameEn() {
        return menuNameEn;
    }

    public void setMenuNameEn(String menuNameEn) {
        this.menuNameEn = menuNameEn;
    }

    public String getMenuType() {
        return menuType;
    }

    public void setMenuType(String menuType) {
        this.menuType = menuType;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public String getPolicy() {
        return policy;
    }

    public Policy getGroupPolicyAction() {
        return groupPolicyAction;
    }

    public void setGroupPolicyAction(Policy groupPolicyAction) {
        this.groupPolicyAction = groupPolicyAction;
    }
    
    

    public void setPolicy(String policy) {
        this.policy = policy;
        if (this.policy!=null){
            this.policyAction.setCanAdd(this.getPolicy().indexOf(Constanta.POLICY_INSERT)>-1);
            this.policyAction.setCanOpen(this.getPolicy().indexOf(Constanta.POLICY_OPEN)>-1);
            this.policyAction.setCanEdit(this.getPolicy().indexOf(Constanta.POLICY_UPDATE)>-1);
            this.policyAction.setCanDelete(this.getPolicy().indexOf(Constanta.POLICY_DELETE)>-1);
            this.policyAction.setCanPrint(this.getPolicy().indexOf(Constanta.POLICY_PRINT)>-1);
            this.policyAction.setCanApprove(this.getPolicy().indexOf(Constanta.POLICY_APPROVAL)>-1);
            
            this.groupPolicyAction.setCanAdd(false);
            this.groupPolicyAction.setCanApprove(false);
            this.groupPolicyAction.setCanDelete(false);
            this.groupPolicyAction.setCanEdit(false);
            this.groupPolicyAction.setCanOpen(false);
            this.groupPolicyAction.setCanPrint(false);
            /*for (int i=0;i<this.policy.length();i++){            
                switch (i){
                    case 0: this.policyAction.setCanAdd(this.getPolicy().charAt(i)=='1');break;
                    case 1: this.policyAction.setCanEdit(this.getPolicy().charAt(i)=='1');break;
                    case 2: this.policyAction.setCanDelete(this.getPolicy().charAt(i)=='1');break;
                    case 3: this.policyAction.setCanPrint(this.getPolicy().charAt(i)=='1');break;
                    case 4: this.policyAction.setCanApprove(this.getPolicy().charAt(i)=='1');break;
                }
            }
            * 
            */
        }
        
    }

    public Policy getPolicyAction() {
        return policyAction;
    }

  
    
    

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    
    
}
